<template>
  <el-row type="flex" justify="space-between" align="middle" style="width:100%;height: 40px">
    <el-col>
      <strong v-if="isCompany">{{ nodeData.name }}</strong>
      <span v-else>{{ nodeData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ nodeData.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown class="cz">
            <span>
              操作<i class="el-icon-arrow-down" />
            </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addDepartClick">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isCompany" @click.native="editDepartClick">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!isCompany" @click.native="delDepartClick">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartmentsAPI } from '@/api/departments'
export default {
  // 接收父组件传递的参数
  props: {
    // 传递的数据是一个对象
    nodeData: {
      type: Object,
      // 是否必须传递
      required: true
    },
    isCompany: {
      type: Boolean,
      required: true
    },
    // 接收父组件渲染组织架构页面函数getDepartment
    getDepartment: {
      type: Function,
      required: true
    }
  },
  methods: {
    addDepartClick() {
      this.$emit('addDepartClick', this.nodeData)
    },
    editDepartClick() {
      this.$emit('editDepartClick', this.nodeData)
    },
    async delDepartClick() {
      await this.$confirm('确定要删除该数据吗？')
      // 发送删除请求
      await delDepartmentsAPI(this.nodeData.id)
      // 删除成功提示
      this.$message.success('删除部门成功！')
      // 刷新页面
      this.getDepartment()
    }

  }
}
</script>

<style>

</style>
